package logic

import (
	"context"

	"tianji-network/common/errorx"
	"tianji-network/service/gateway/api/internal/svc"
	"tianji-network/service/gateway/api/internal/types"
	"tianji-network/service/gateway/api/tools"
	"tianji-network/service/satellite/rpc/satellite"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSatelliteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetSatelliteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSatelliteLogic {
	return &GetSatelliteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetSatelliteLogic) GetSatellite(req *types.SatelliteReq) (resp *types.SatelliteReply, err error) {
	//根据id查询单个卫星
	satelliteOne, err := l.svcCtx.SatelliteRpc.Get(l.ctx, &satellite.IdReq{Id: req.Id})
	if err != nil {
		return nil, errorx.NewDefaultError("查询失败")
	}
	return tools.ProtoConvertToResp(satelliteOne), nil
}
